<%@page import="com.thinkgem.jeesite.common.utils.ali.config.mobile.AlipayConfig"%>
<%@page import="com.thinkgem.jeesite.common.utils.ali.util.mobile.AlipaySubmit"%>
<%@page import="com.thinkgem.jeesite.modules.config.entity.ali.ConfigAlipay"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.Map"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>支付宝即时到账交易接口</title>
	</head>
	<%
		////////////////////////////////////请求参数//////////////////////////////////////

        //商户订单号，商户网站订单系统中唯一订单号，必填
        String coNum = new String(request.getParameter("coNum").getBytes("ISO-8859-1"),"UTF-8");

        //付款金额，必填
        String txnAmt = new String(request.getParameter("txnAmt").getBytes("ISO-8859-1"),"UTF-8");
        String body = (String)request.getAttribute("body");
        String subject =  (String)request.getAttribute("subject");;
        
        ConfigAlipay configAlipay = (ConfigAlipay)request.getAttribute("configAlipay");
        int index = txnAmt.indexOf(".");
		if (index < 0) {
			txnAmt = txnAmt + ".00";
		} else if ((txnAmt.length() - index) < 3) {
			if ((txnAmt.length() - index) == 2) {
				txnAmt = txnAmt + "0";
			} else if ((txnAmt.length() - index) == 1) {
				txnAmt = txnAmt + "00";
			}
		} else if ((txnAmt.length() - index) > 3) {// 保留小数超过两位则去除多余的
			txnAmt = txnAmt.substring(0, index + 3);
		}
		//////////////////////////////////////////////////////////////////////////////////
		
		//把请求参数打包成数组
		Map<String, String> sParaTemp = new HashMap<String, String>();
		sParaTemp.put("_input_charset", AlipayConfig.input_charset);
		sParaTemp.put("app_pay","Y");//启用此参数可唤起钱包APP支付。
		sParaTemp.put("body", body+"_gainseng_session_id_"+request.getSession().getId());
		sParaTemp.put("notify_url", AlipayConfig.notify_url);
		sParaTemp.put("out_trade_no", coNum);
		sParaTemp.put("partner", AlipayConfig.partner);
		sParaTemp.put("payment_type", AlipayConfig.payment_type);
		sParaTemp.put("return_url", AlipayConfig.return_url);
		sParaTemp.put("seller_id", AlipayConfig.seller_id);
		sParaTemp.put("service", AlipayConfig.service);
		sParaTemp.put("subject", coNum);
		sParaTemp.put("total_fee", txnAmt);
		//
		//其他业务参数根据在线开发文档，添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1
		//如sParaTemp.put("参数名","参数值");
		//建立请求
		String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,"get","确认");
		out.println(sHtmlText);

	%>
	<body>
	</body>
</html>
